package com.coco.service;

import com.coco.dao.MsgMapper;
import com.coco.dao.OrderMapper;
import com.coco.entity.Msg;
import com.coco.entity.Order;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
public class TranctionService {


    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private MsgMapper msgMapper;

    @Transactional
    @ShardingTransactionType(TransactionType.BASE)
    public void save() {
        Order order = new Order();
        order.setUserId(6); //m0数据库
        order.setOrderAmount(BigDecimal.valueOf(10));
        order.setOrderStatus(1);
        orderMapper.saveData(order);
        Msg msg = new Msg();
        msg.setId(3);
        msg.setName("javasparkcocococococo");
        msgMapper.addMsg(msg);
    }
}
